//-----------------------------------------------------------------------
// <copyright file="Context.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the Context class.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Benchmarks.Manners.Model
{
    using System;

    /// <summary>
    /// Miss Manners - Context class
    /// </summary>
    /// <remarks>
    /// This class serves a dual purpose withing the Miss Manners 
    /// benchmark test.   It provides a 'state' property which is
    /// used to control the meta-cycle of the test through different
    /// rules.   In addition, it serves as a lirary of helper methods
    /// including factory methods for other class types.
    /// </remarks>
    public class Context
    {
        /// <summary>
        /// The current state value of the context.
        /// </summary>
        private static string state;

        /// <summary>
        /// Gets or sets the state property is used to control the meta-cycle of the
        /// Miss manners benchmark test as the engine evaluates facts
        /// against a sequence of rules.
        /// </summary>
        public static string State
        {
            get
            {
                return state;
            }

            set
            {
                state = value;
            }
        }

        #region Factory methods

        /* The following methods are factory methods used to create instances
         * of fact classes
         * */

        /// <summary>
        /// Create an initialized Seating instance.
        /// </summary>
        /// <param name="seat1">Number of left seat.</param>
        /// <param name="name1">Name of left guest.</param>
        /// <param name="name2">Name of right guest.</param>
        /// <param name="seat2">Number of right seat.</param>
        /// <param name="id">Seating ID.</param>
        /// <param name="pid">Path ID.</param>
        /// <param name="pathDone">Path done flag - yes | no.</param>
        /// <returns>
        /// An initialized Seating instance.
        /// </returns>
        public static Seating CreateSeating(int seat1, string name1, string name2, int seat2, int id, int pid, string pathDone)
        {
            return new Seating(seat1, name1, name2, seat2, id, pid, pathDone);
        }

        #endregion

        #region Print functions

        /* The following helper methods are used to output messages  
         * to the console.   They are invoked within various rules.
         * */

        /// <summary>
        /// Prints a message for the assign_first_seat rule.
        /// </summary>
        /// <param name="name">Name of the first seated guest.</param>
        /// <param name="count">Current count value.</param>
        public static void PrintResultAssignFirstSeat(string name, int count)
        {
            Console.WriteLine(@"seat 1 {0} {0} 1 {1} 0 1", name, count);
        }

        /// <summary>
        /// Prints a message for the find_seating rule.
        /// </summary>
        /// <param name="seat">Seat number.</param>
        /// <param name="name1">Name of left guest.</param>
        /// <param name="name2">Name of right guest.</param>
        public static void PrintResultFindSeating(int seat, string name1, string name2)
        {
            Console.WriteLine(@"seat {0} {1} {2}", seat, name1, name2);
        }

        /// <summary>
        /// Prints a message for the are_we_done rule.
        /// </summary>
        public static void PrintResultAreWeDone()
        {
            Console.WriteLine(@"\r\nYes, we are done!!");
        }

        /// <summary>
        /// Prints a message for the print_results rule.
        /// </summary>
        /// <param name="name">Name of seated guest.</param>
        /// <param name="seat">Seat number of the given guest.</param>
        public static void PrintResults(string name, int seat)
        {
            Console.WriteLine(@"{0} {1}", name, seat);
        }

        /// <summary>
        /// Returns a text representation of the Context object.
        /// </summary>
        /// <returns>
        /// A text representation of the Context object.
        /// </returns>
        public override string ToString()
        {
            return string.Format("(context (state {0}))", state);
        }

        #endregion
  }
}
